package com.wnxy.common.base;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

@Data
@NoArgsConstructor
@AllArgsConstructor
@ApiModel("分页返回")
@Builder
public class PageBean<T> {
    @ApiModelProperty("当前页")
    private long current;
    @ApiModelProperty("页大小")
    private long size;
    @ApiModelProperty("总记录数")
    private long total;
    @ApiModelProperty("总页数")
    private long pages;
    @ApiModelProperty("页数据")
    private List<T> list;


    public static <T> PageBean<T> fill(Page<T> page) {
        return PageBean.<T>builder()
                .current(page.getCurrent())
                .size(page.getSize())
                .total(page.getTotal())
                .pages(page.getPages())
                .list(page.getRecords())
                .build();
    }

}
